package com.barney.support.jpa;

import javax.persistence.PrePersist;
import javax.persistence.PreUpdate;

import com.barney.support.domain.HasPrePersistAndPreUpdate;

/**
 * 저장하기 전과 변경하기 전에 실행해야하는 메소드를 실행하는 엔티티 리스너.
 *
 * <blockquote><pre>
 * &#064;Entity
 * &#064;EntityListeners(PrePersistAndPreUpdateListener.class)
 * pubic class Entity implements Serializable, HasPrePersistAndPreUpdate {
 * ...
 * }
 * </pre></blockquote>
 *
 * @see HasPrePersistAndPreUpdate
 */
public class PrePersistAndPreUpdateListener {

	@PrePersist
	@PreUpdate
	public void prePersistAndPreUpdate(Object obj) {
		if(obj instanceof HasPrePersistAndPreUpdate) {
			((HasPrePersistAndPreUpdate)obj).prePersistAndPreUpdate();
		}
	}
}
